CFLAGS = -Wall -Werror -g -O2

libcmds = -lpthread -L/usr/local/lib -lglfw3 -lX11 -ldl -lglog -lGL

objs = \
src/core/bsdf.o \
src/core/buffer.o \
src/core/camera.o \
src/core/efloat.o \
src/core/film.o \
src/core/geometry.o \
src/core/heads.o \
src/core/interaction.o \
src/core/light.o \
src/core/material.o \
src/core/object.o \
src/core/optics.o \
src/core/rng.o \
src/core/sampler.o \
src/core/scene.o \
src/core/shader.o \
src/core/shape.o \
src/core/spectrum.o \
src/core/strc.o \
src/core/texture.o \
src/light/area.o \
src/material/diffuse.o \
src/sampler/halton.o \
src/sampler/naive.o \
src/shader/sppm.o \
src/shape/sphere.o \
src/shape/triangle.o \
src/structure/kdtree.o \
src/tools/objreader.o

chen: $(objs)
	g++ src/main.cpp $(CFLAGS) -c -o src/main.o
	g++ $(objs) src/main.o $(libcmds) -o chen
.PHONY : chen

test: $(objs)
	g++ src/testing.cpp $(CFLAGS) -c -o src/testing.o
	g++ $(objs) src/testing.o $(libcmds) -o test
.PHONY : test

%.d: %.cpp
	@set -e; \
	rm -f $@; \
	g++ -MM $< > $@.$$$$; \
	sed 's,.*:,$*.o : ,g' < $@.$$$$ >> $@; \
	echo '\tg++ $$< -c -o $$@ $(CFLAGS)\n' >> $@;\
	g++ -MM $< > $@.$$$$; \
	sed 's,.*:,$@ : ,g' < $@.$$$$ >> $@; \
	rm -f $@.$$$$

include $(objs:%.o=%.d)

clean: 
	rm -f `find ./src -name '*.d'`
	rm -f `find ./src -name '*.o'`
	rm -f chen

.PHONY : clean